package factory.simplefactory.order;

import factory.simplefactory.dumpling.Dumpling;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author desire
 */
public class Order {


    //public Order(){
    //    Dumpling dumpling = null;
    //    String orderType = "";
    //    do{
    //        orderType = getType();
    //        if("jiucai".equals(orderType)){
    //            dumpling = new JiuCaiDumpling();
    //            dumpling.setName("韭菜饺子");
    //        }else if("baicai".equals(orderType)){
    //            dumpling = new BaiCaiDumpling();
    //            dumpling.setName("白菜饺子");
    //        }else{
    //            break;
    //        }
    //        dumpling.prepare();
    //        dumpling.pack();;
    //        dumpling.cook();
    //        System.out.println("制作完成~~~~");
    //    }while (true);
    //
    //}
    public Order(SimpleFactory simpleFactory){
        setSimpleFactory(simpleFactory);
    }

    SimpleFactory simpleFactory;

    public void setSimpleFactory(SimpleFactory simpleFactory){
        Dumpling dumpling = null;
        String orderType = "";
        do{
            orderType = getType();
            dumpling = simpleFactory.createDumpling(orderType);
            if(dumpling != null){
                dumpling.prepare();
                dumpling.pack();;
                dumpling.cook();
                System.out.println("制作完成~~~~");
            }else{
                System.out.println("无此类型");
            }

        }while (true);

    }

    public String getType(){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("input dumpling type:");
        String str = "";
        try {
            str = reader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }



}
